package com.auto.code.service.impl;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.auto.code.dao.TemplatePathDAO;
import com.auto.code.domain.TemplatePathDO;
import com.auto.code.domain.TemplatePathDTO;
import com.auto.code.service.TemplatePathService;
import com.auto.code.util.MapUtils;
import com.auto.code.util.ObjectClone;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

@Service
public class TemplatePathServiceImpl implements TemplatePathService {
	private static final Logger logger = LoggerFactory.getLogger(TemplatePathServiceImpl.class);

	@Autowired
	private TemplatePathDAO templatePathDAO;

	@Override
	public int deleteById(Long id) {
		return templatePathDAO.deleteById(id);
	}

	@Override
	public int create(TemplatePathDTO record) {
		TemplatePathDO entity = new TemplatePathDO();
		BeanUtils.copyProperties(record, entity);
		return templatePathDAO.insert(entity);
	}

	@Override
	public TemplatePathDTO getById(Long id) {
		TemplatePathDTO entity = new TemplatePathDTO();
		BeanUtils.copyProperties(templatePathDAO.getById(id), entity);
		return entity;
	}

	@Override
	public int update(TemplatePathDTO record) {
		TemplatePathDO entity = new TemplatePathDO();
		BeanUtils.copyProperties(record, entity);
		return templatePathDAO.update(entity);
	}

	@Override
	public PageInfo<TemplatePathDTO> queryPage(TemplatePathDTO templateDTO) {
		PageHelper.startPage(templateDTO.getPageNum(), templateDTO.getPageSize());
		List<TemplatePathDO> templateDOS = templatePathDAO.queryList(MapUtils.parseMap(templateDTO));
		List<TemplatePathDTO> templateDTOList = ObjectClone.cloneList(templateDOS, TemplatePathDTO.class);
		return new PageInfo<>(templateDTOList);
	}

	@Override
	public List<TemplatePathDTO> queryList(TemplatePathDTO templateDTO) {
		List<TemplatePathDO> templateDOS = templatePathDAO.queryList(MapUtils.parseMap(templateDTO));
		List<TemplatePathDTO> templateDTOList = ObjectClone.cloneList(templateDOS, TemplatePathDTO.class);
		return templateDTOList;
	}

}
